package com.example.administrator.zjyapp.SQLiteDatabase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by Administrator on 2017/4/8.
 */

public class dbHelper extends SQLiteOpenHelper{
    public static final String KEY_BOOK_NAME = "name";
    public static final String KEY_BOOK_TYPE = "type";
    public static final String KEY_BOOK_PRICE = "price";
    public static final String DATA_BASE_NAME = "bookDb";
    public static final int VERSION = 1;

    public dbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }
    /**
     * 当数据库首次创建时执行该方法，一般将创建表等初始化操作放在该方法中执行.
     * 重写onCreate方法，调用execSQL方法创建表
     * */
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("create table" + DATA_BASE_NAME
                + "书名 primary key,"
                + "类型 varchar,"
                + "价格 integer)");
    }

    @Override
    //当打开数据库时传入的版本号与当前的版本号不同时会调用该方法
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }
}
